﻿using Newtonsoft.Json;

namespace KAs.Utils.Http;

public static class HttpHelp
{
    public static async Task<T> GetAsync<T>(string url, IDictionary<string, string> dicParams)
    {
        var httpClient = new HttpClient();
        var resMsg = await httpClient.GetAsync(url + DicToUrlParams(dicParams));
        return JsonConvert.DeserializeObject<T>(await resMsg.Content.ReadAsStringAsync());
    }

    private static string DicToUrlParams(IDictionary<string, string> dicParams)
    {
        var kvEnumer = dicParams.Select(x => $"{x.Key}={x.Value}");
        return "?" + string.Join("&", kvEnumer);
    }
}
